package com.herui.sdyu_lib.adapter.recycle_view;

import android.content.Context;
import android.view.ViewGroup;

import com.herui.sdyu_lib.adapter.recycle_view.base.ViewHolder;

import java.util.List;


/**
 * Created by amanda.shan on 2016/11/24.
 */
public abstract class MultiItemCommonAdapter<T> extends CommonAdapter<T> {
    protected MultiItemTypeSupport<T> mMultiItemTypeSupport;

    public MultiItemCommonAdapter(Context context, List<T> datas,
                                  MultiItemTypeSupport<T> multiItemTypeSupport) {
        super(context, -1, datas);
        mMultiItemTypeSupport = multiItemTypeSupport;
    }

    @Override
    public int getItemViewType(int position) {
        return mMultiItemTypeSupport.getItemViewType(position, mDatas.get(position));
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        int layoutId = mMultiItemTypeSupport.getLayoutId(viewType);
        ViewHolder viewHolder = ViewHolder.createViewHolder(mContext, parent, layoutId);
        onViewHolderCreated(viewHolder, viewHolder.getConvertView());
        setListener(parent, viewHolder, viewType);
        return viewHolder;
    }

}